package com.shoulder.boot.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shoulder.boot.system.dto.DictAddDTO;
import com.shoulder.boot.system.dto.DictModDTO;
import com.shoulder.boot.system.dto.DictQueryDTO;
import com.shoulder.boot.system.service.DictService;
import com.shoulder.boot.system.vo.DictVo;
import com.shoulder.core.api.ApiResult;
import com.shoulder.core.fetch.BaseIds;
import com.shoulder.core.page.PageSchema;
import com.shoulder.log.annotation.LogAnnotation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 字典信息管理
*/
@RestController
@AllArgsConstructor
@RequestMapping("/admin/api/v1/system/dict")
public class DictController {

    private final DictService dictService;

    /**
    * 添加字典信息
    *
    * @param addDTO 字典信息添加请求体
    * @return ApiResult<Object>
    * @author unKnown
    */
    @PostMapping
    @LogAnnotation(type = "添加字典信息")
    public ApiResult<Object> add(@RequestBody @Validated DictAddDTO addDTO) {
        this.dictService.add(addDTO);
        return ApiResult.ok();
    }

    /**
    * 修改字典信息
    *
    * @param modDTO 字典信息修改请求体
    * @return ApiResult<Object>
    * @author unKnown
    */
    @PutMapping
    @LogAnnotation(type = "修改字典信息")
    public ApiResult<Object> mod(@RequestBody @Validated DictModDTO modDTO) {
        this.dictService.mod(modDTO);
        return ApiResult.ok();
    }

    /**
    * 查询字典信息分页数据
    *
    * @param queryDTO 字典信息查询请求体
    * @return 字典信息分页数据
    * @author unKnown
    */
    @LogAnnotation(type = "字典信息分页查询", record = false)
    @PostMapping("/page")
    public ApiResult<PageSchema<DictVo>> pageQuery(@RequestBody DictQueryDTO queryDTO) {
        Page<DictVo> page = this.dictService.pageQuery(queryDTO);
        return ApiResult.ok(new PageSchema<>(page.getTotal(), page.getRecords()));
    }

    /**
    * 查询字典信息列表数据
    *
    * @param queryDTO 字典信息查询请求体
    * @return 字典信息列表数据
    * @author unKnown
    */
    @LogAnnotation(type = "字典信息列表查询", record = false)
    @PostMapping("/list")
    public ApiResult<List<DictVo>> list(@RequestBody DictQueryDTO queryDTO) {
        List<DictVo> list = this.dictService.listQuery(queryDTO);
        return ApiResult.ok(list);
    }

    /**
    * 批量删除字典信息
    *
    * @param baseIds  字典信息id集合
    * @return ApiResult<Object>
    * @author unKnown
    */
    @PostMapping("/rm")
    @LogAnnotation(type = "批量删除字典信息")
    public ApiResult<Object> delete(@RequestBody @Validated BaseIds<String> baseIds) {
        this.dictService.batchDel(baseIds);
        return ApiResult.ok();
    }


    /**
    * 根据id删除字典信息
    *
    * @param id 字典信息id
    * @return ApiResult<Object>
    * @author unKnown
    */
    @DeleteMapping("/{id}")
    @LogAnnotation(type = "删除字典信息")
    public ApiResult<Object> del(@PathVariable String id) {
        this.dictService.del(id);
        return ApiResult.ok();
    }


    /**
    * 批量查询字典信息
    *
    * @param baseIds  字典信息id集合
    * @return 字典信息列表数据
    * @author unKnown
    */
    @PostMapping("/look")
    @LogAnnotation(type = "批量查询字典信息", record = false)
    public ApiResult<List<DictVo>> looks(@RequestBody BaseIds<String> baseIds) {
        List<DictVo> list = this.dictService.looks(baseIds);
        return ApiResult.ok(list);
    }

    /**
    * 根据id获取字典信息
    *
    * @param id 字典信息id
    * @return 字典信息
    * @author unKnown
    */
    @GetMapping("/{id}")
    @LogAnnotation(type = "根据id查询字典信息", record = false)
    public ApiResult<DictVo> look(@PathVariable String id) {
        DictVo look = this.dictService.look(id);
        return ApiResult.ok(look);
    }
}